<?php
// +----------------------------------------------------------------------
// | 网站首页
// +----------------------------------------------------------------------

namespace Home\Controller;
use Common\Controller\Base;
use Common\Model\Model;

class IndexController extends Base {

    protected $indextjwork=array();
    protected $indextjnews=array();


    public function index(){

        //测试用,清空缓存
        cache('',null);

        //幻灯片推荐作品
        $workModel=D('Home/Works');
        $this->assign('indextjwork',$workModel->indextjwork());

        //新闻模块
        //单条新闻
        $firstnews=M('News')->field('title,id')->where(array('iftj'=>true,'status'=>true))->order('sort DESC')->limit(1)->find();
        $this->assign('firstnews',$firstnews);
        $this->assign('indextjnews',D('Home/News')->indextjnews());

        //每日新秀
        $this->assign('indexxinxiu',$workModel->worksxinxiu());

        //中间广告位
        $this->assign('indexmidad',parent::getAdvert(1,1,0,5));

        //左侧广告位
        $this->assign('indexleftad',parent::getAdvert(1,2,0,1));

        //类别每日一荐
        $this->assign('indexcatetj',$workModel->cateonework());

        //焙友动态
        $this->userDynamicData=D('Home/User')->userDynamic(5);

        //热门活动
        $this->assign('activitytj',D('Home/Activity')->activitytj(2));

        //右边上侧
        $this->assign('rightopad',parent::getAdvert(1,3,0,1));

        //右边广告
        $this->assign('indexrightad',parent::getAdvert(1,3,1,3));

        //分享达人
        $this->assign('sharedaren',D('Home/User')->sharedaren(5,$this->userid));

        //判断是否签到
        $stime=strtotime(date('Y-m-d 00:00:00'));
        $etime=strtotime(date('Y-m-d 23:59:59'));
        $where['userid']= array('EQ',$this->userid);
        $where['create_time']=array(array('GT',$stime),array('LT',$etime),'and');
        $where['action']=array('EQ','sign');

        $map['create_time']=array(array('GT',$stime),array('LT',$etime),'and');
        $map['action']=array('EQ','sign');
        $this->mysign=getCount('UserDynamic',$where);
        $this->signcount=getCount('UserDynamic',$map);

        $this->display();
    }


    /**
     * 类别列表
     */
    public function category(){
        $cateid=I('get.cid');
        if(empty($cateid)){
            $this->_empty();
        }

        $where['cateid']=$cateid;
        $where['type'] = 1;
        $where['status']=true;
        $count = M('Works')->where($where)->count();
        $page = $this->Pages($count, 10);
        $pageurl='?page='.urlencode('[PAGE]');
        $page->url     = __APP__.'/category/'.$cateid.'/'.$pageurl;
        $this->pagecount=$page->totalRows/$page->listRows;
        
        $list=D('Home/Works')->relation(array('User','Category'))->where($where)->order('iftj DESC,workid DESC')->limit($page->firstRow . ',' . $page->listRows)->select();

        $this->assign('catename',$list[0]['catename']);
        $this->assign('list',$list);
        $this->assign("Page", $page->show());

        $this->assign('midad',parent::getAdvert(3,1,0,1));
        //右上角广告
        $this->assign('righttopad',parent::getAdvert(3,3,0,1));

        //热门活动
        $this->assign('activitytj',D('Home/Activity')->activitytj(2));

        //焙友动态
        $this->userDynamicData=D('Home/User')->userDynamic(5);

        //分享达人
        $this->assign('sharedaren',D('Home/User')->sharedaren(5,$this->userid));

        $this->display();
    }





}